﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Riel_Gestion.rielDataSetTableAdapters;
using System.Data;

namespace Riel_Gestion
{

    class LocalProperties
    {
        private static LocalProperties INSTANCE;
        private Dictionary<String, String> properties;
        private rielDataSet.PROPERTYDataTable dt;
        private PROPERTYTableAdapter tableProp;

        private LocalProperties()
        {
            properties = new Dictionary<string, string>();
            dt = new rielDataSet.PROPERTYDataTable();
            tableProp = new PROPERTYTableAdapter();
            tableProp.Fill(dt);

            foreach (DataRow row in dt.Rows)
            {
                properties.Add(row["ID"].ToString(), row["VALOR"].ToString());
            }            
        }

        public static LocalProperties getInstance()
        {
            if (INSTANCE == null)
                return new LocalProperties();
            else
                return INSTANCE;
        }

        public String getProperty(String id)
        {
            return properties[id];
        }

        public void setProperty(String id, String valor)
        {
            properties[id] = valor;
            tableProp.UpdateQueryByID(valor, id);
        }

        public void addProperty(String id, String valor)
        {
            properties.Add(id, valor);
            tableProp.Insert(id, valor);
        }

    }
}
